package com.acme.domain;

import java.util.ArrayList;
import com.acme.domain.client.*;
import com.acme.exceptions.ClientExistsException;

public class Bank{

	private final ArrayList<Client> clients = new ArrayList<Client>();
	
	public Client addClient(final Client client) throws ClientExistsException {

		if (getClientByName(client.getName()) != null) {
			throw new ClientExistsException("Client with name: "
					+ client.getName() + " has already registered in the bank");
		}
		clients.add(client);

		return client;
	}
	
	public Client getClientByName(String clientName){
		for (int i = 0; i < clients.size(); i++) {
			if (clients.get(i).getName().compareToIgnoreCase(clientName) == 0)
				return clients.get(i);
		}
		return null;
	}
}